package com.example.boot.controller;

import com.example.common.Result;
import com.example.pojo.dto.JoinDTO;
import com.example.pojo.utils.ApprocalPageResult;
import com.example.pojo.vo.ApprovalVO;
import com.example.service.ApprovalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * TODO
 *
 * @author ding
 * @since 2024/7/13
 */
@RestController
@Slf4j
@RequestMapping("/approval")
@Api(tags = "审批相关接口")
public class ApprovalController {

    @Autowired
    private ApprovalService approvalService;

    @ApiOperation("分页获取审批信息")
//    @PreAuthorize("hasAuthority('APPROVAL_PAGEQUERY')")
    @GetMapping("/selectPage")
    public Result selectPage(
            @ApiParam("当前页数") @RequestParam(defaultValue = "1") Integer pageNum,
            @ApiParam("页面数据大小") @RequestParam(defaultValue = "10") Integer pageSize) {
        ApprocalPageResult page = approvalService.selectPage(pageNum, pageSize);
        return Result.success(page);
    }

    /**
     * 进行审批
     */
    @ApiOperation("进行审批")
//    @PreAuthorize("hasAuthority('APPROVAL_APPLY')")
    @PostMapping("/apply")
    public Result apply(@ApiParam("审批信息") @RequestBody ApprovalVO approvalVO) {
        approvalService.apply(approvalVO);
        return Result.success();
    }

    @ApiOperation("分页获取我的处理信息")
//    @PreAuthorize("hasAuthority('APPROVAL_MYHANDEL')")
    @GetMapping("/selectMyHandle")
    public Result selectMyHandle(
            @ApiParam("当前页数") @RequestParam(defaultValue = "1") Integer pageNum,
            @ApiParam("页面数据大小") @RequestParam(defaultValue = "10") Integer pageSize) {
        ApprocalPageResult page = approvalService.selectMyHandle(pageNum, pageSize);
        return Result.success(page);
    }

    @ApiOperation("分页获取我的请求")
//    @PreAuthorize("hasAuthority('APPROVAL_MYSUBMIT')")
    @GetMapping("/selectMySubmit")
    public Result selectMySubmit(
            @ApiParam("当前页数") @RequestParam(defaultValue = "1") Integer pageNum,
            @ApiParam("页面数据大小") @RequestParam(defaultValue = "10") Integer pageSize) {
        ApprocalPageResult page = approvalService.selectMySubmit(pageNum, pageSize);
        return Result.success(page);
    }

    @ApiOperation("入职申请")
    @PostMapping("/addJoin")
    public Result addJoinTeam(@RequestBody JoinDTO joinDTO) {
        approvalService.addJoinTeam(joinDTO);
        return Result.success();
    }


}
